<script lang="ts" setup>
import { getNutritionPlan } from "../service";
import { IResponseData } from "@/@types/utils.request";

const props = defineProps({
	modelValue: {
		type: Boolean,
		default: false,
	},
	orderNo: {
		type: String,
		default: "",
	},
});

const emit = defineEmits<{
	(e: "update:modelValue", value: boolean): void;
}>();
const visible = computed({
	get() {
		return props.modelValue;
	},
	set(val) {
		emit("update:modelValue", !!val);
	},
});
const orderNo = computed(() => props.orderNo);

const getFetch = async () => {
	try {
		console.log("getFetch", orderNo.value);
		const response: IResponseData<any> = await getNutritionPlan({
			orderNo: orderNo.value,
		} as any);
		const { code, msg, data } = response;
		if (code === 0) {
			viewData.value = data;
		} else {
			ElMessage({
				message: msg,
				type: "error",
			});
		}
	} catch (error: any) {
		console.log(error);
	}
};

const viewData = ref({
	id: 1,
	sex: 1,
	patientName: "张三",
	patientAge: "",
	diagnosisResult: "",
	nutritionAdvise: "",
	nutSchemeProductList: [],
});
</script>

<template>
	<el-dialog v-model="visible" title="营养方案 " width="520px" @open="getFetch">
		<el-form :model="viewData" label-width="100px">
			<el-form-item label="姓名：">{{ viewData.patientName }}</el-form-item>
			<el-form-item label="年龄：">{{ viewData.patientAge }}</el-form-item>
			<el-form-item label="性别：">{{ viewData.sex === 1 ? "男" : "女" }}</el-form-item>
			<el-form-item label="病情诊断：">{{ viewData.diagnosisResult }}</el-form-item>
			<el-form-item label="营养建议：">{{ viewData.nutritionAdvise }}</el-form-item>
			<el-form-item label="推荐营养品：">
				<el-table :data="viewData.nutSchemeProductList" border>
					<el-table-column label="产品名称" prop="productName" />
					<el-table-column label="用法用量" prop="productUsage" />
				</el-table>
			</el-form-item>
		</el-form>
	</el-dialog>
</template>
